package com.sen.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sen.dao.DruginfoDao;
import com.sen.entity.DruginfoEntity;
import com.sen.service.DruginfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("druginfoService")
public class DruginfoServiceImpl extends ServiceImpl<DruginfoDao, DruginfoEntity> implements DruginfoService {

    @Autowired
    DruginfoDao druginfoDao;

    @Override
    public IPage<DruginfoEntity> queryAllDrug(Page<DruginfoEntity> page, Map<String,String> druginfo) {
        if (druginfo.get("tid")!=null){
            String tid = druginfo.get("tid");
            List<Integer> types = druginfoDao.queryType(tid);
            return druginfoDao.queryAllDrug(page,druginfo,types);
        }
        else {
            return druginfoDao.queryAllDrug(page,druginfo,null);
        }

    }
    //采购查询仓库
    @Override
    public IPage<DruginfoEntity> queryAllDrug2(Page<DruginfoEntity> page, Map<String, String> druginfo) {
        QueryWrapper<DruginfoEntity> wrapper = new QueryWrapper<>();
        if (druginfo.get("tid")!=null){
            wrapper.eq("di.tid", druginfo.get("tid"));
        }
        if (druginfo.get("cid")!=null){
            wrapper.eq("di.cid", druginfo.get("cid"));
        }
        if (druginfo.get("dname")!=null){
            wrapper.like("dname", druginfo.get("dname"));
        }
        return druginfoDao.queryAllDrug2(page,wrapper);
    }
    @Override
    public IPage<DruginfoEntity> querList(Page<DruginfoEntity> page, Map<String, String> druginfo) {
        if (druginfo.get("tid")!=null){
            String tid = druginfo.get("tid");
            List<Integer> types = druginfoDao.queryType(tid);
            return druginfoDao.queryList(page,druginfo,types);
        }
        else{
            return druginfoDao.queryList(page,druginfo,null);
        }
    }

    @Override
    public String getMedno() {
        return druginfoDao.getMedno();
    }

    @Override
    public List<DruginfoEntity> queryWarehouse(Integer mid) {
        return druginfoDao.queryWarehouse(mid);
    }
}
